package com.pxxy.springboot.webcase.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

/******************
 * @Author yejf
 * @Description TODO
 */
public class SpecialLetterRequest extends HttpServletRequestWrapper {

    private HttpServletRequest request;

    public SpecialLetterRequest(HttpServletRequest request) {
        super(request);
        //保存原始的请求对象，以备后用
        this.request = request;
    }

    //重写你感兴趣的方法

    @Override
    public String getParameter(String name) {
        //替换特殊字符
        //1. 获取原始的请求数据
        String value = this.request.getParameter(name);
        //
        if(value != null) {
            //2. 把特殊字符替掉,替换成空白
            String regex = "[^0-9a-zA-Z\u4e00-\u9fa5./\\-，,。？“”]+";
            value = value.replaceAll(regex, "");
        }
        //3. 返回
        return value;
    }
}
